package com.hongxin.nw.netty.mq_info;

import com.alibaba.fastjson.JSONObject;
import com.hongxin.nw.netty.model.Transfer;
import com.hongxin.nw.netty.model.analysis.info.DTmmdna1;
import com.hongxin.nw.netty.utils.JSONUtils;
import com.hongxin.nw.netty.utils.ModifyJsonKeyUtil;
import com.hongxin.nw.netty.values.Catalogue;
import com.hongxin.nw.netty.values.StaticValue;

import java.util.List;

/**
 * @remark 设备功率信息(直流)
 * @author: GuoXiaolin
 * @date 2019/6/21 19:21
 * @Version 1.0
 * @Descibe
 */
public class EquipTypeInfo implements IMq {
    @SuppressWarnings("unchecked")
    @Override
    public JSONObject sendMqInfo(Transfer transfer)  throws Exception{
        List<DTmmdna1> myl = (List<DTmmdna1>) transfer.getObj();
        JSONObject json =  new JSONObject();
        json.put(Catalogue.MQ_CODE, transfer.getCode());
        json.put(Catalogue.MQ_GUN, myl.get(0).getGun() + 1);
        json.put(Catalogue.HXCMD, Catalogue.CMD204);
        for (DTmmdna1 dataItem : myl) {
            json.put(dataItem.getInfoAdr(), dataItem.getValue());
        }
        JSONObject mqJson = ModifyJsonKeyUtil.removeEmptyKey(json);
        return JSONUtils.getRoot(0, StaticValue.VAL_28, mqJson);
    }
}
